#ifndef PROPS_H
#define PROPS_H

//Map Props statistics
int max_static_prop, max_action_prop, top_prop; //Describes the Order of static prop drawing based on the spawning order of the graphic. (Array-Queue)

//A prop that is currently static;
class Static_Prop
{
 public:
  hgeSprite* Spr_Static_Prop;
  float X_Position, Y_Position, Rotation;
// public:
  bool in_use;
  Static_Prop();
  void Create(hgeSprite* Prop, float PosX, float PosY, float rot);
  void render();
};

Static_Prop::Static_Prop() {}

void Static_Prop::Create(hgeSprite* Prop, float PosX, float PosY, float rot)
{
 Spr_Static_Prop = Prop;
 X_Position      = PosX;
 Y_Position      = PosY;
 Rotation        = rot;
}

void Static_Prop::render()
{
 if(in_use) Spr_Static_Prop->RenderEx(X_Position - Camera_X + Screen_Width/2, Y_Position - Camera_Y + Screen_Height/2, Rotation);
}

//A prop that is currently in motion;
class Action_Prop
{
 public:
  hgeSprite* Spr_Action_Prop;
  //Positional Data
  float     X_Position,     Y_Position;
  float     X_Velocity,     Y_Velocity;
  float X_Acceleration, Y_Acceleration;
  float    rotate_rate,   cur_rotation; //Amount of degrees it should rotate in a second
  float      stop_time; //Amount of time alloted until the Action_Prop is shifted to a static prop
  bool  send_to_static; //If send to static is true, then upon death, the prop is transferred to a static prop memory space.
 //public:
  bool  in_use;
  Action_Prop();
  void Create(hgeSprite* Prop, float PosX, float PosY, float VelX, float VelY, float AccX, float AccY, float r_rate, float cur_rot, float death_time, bool send_to_static);
  void update(float delta_time, Static_Prop* Prop);
  void render();
};

Action_Prop::Action_Prop() {}

//Creates the prop for render
void Action_Prop::Create(hgeSprite* Prop, float PosX, float PosY, float VelX, float VelY, float AccX, float AccY, float r_rate, float cur_rot, float death_time, bool to_static)
{
 Spr_Action_Prop   = Prop;
 X_Position        = PosX;
 X_Velocity        = VelX;
 X_Acceleration    = AccX;
 Y_Position        = PosY;
 Y_Velocity        = VelY;
 Y_Acceleration    = AccY;
 rotate_rate       = r_rate*M_PI/180; //Converted to radians
 cur_rotation      = cur_rot;
 stop_time         = death_time;
 in_use            = true;
 send_to_static    = to_static;
}

void Action_Prop::update(float delta_time, Static_Prop* Prop)
{
 //First check for completions and send-to-static if needed.
 if(in_use) stop_time = stop_time - delta_time;
 if(stop_time < 0 && in_use)  
 {
  in_use = false; //destroy the prop
  if(send_to_static) 
   {
    top_prop++;
    if(top_prop >= max_static_prop) top_prop = 0;
    Prop[top_prop].Create(Spr_Action_Prop, X_Position, Y_Position, cur_rotation);
    Prop[top_prop].in_use = true;
   }
 }
 //Then perform an update of each object's positions
 //Equation: D = vi*t + .5*a*t^2
 X_Position = X_Position + (X_Velocity*delta_time) + (.5*X_Acceleration*delta_time*delta_time);
 Y_Position = Y_Position + (Y_Velocity*delta_time) + (.5*Y_Acceleration*delta_time*delta_time);
 //Equation: Vf = Vi + a*t
 X_Velocity = X_Velocity + X_Acceleration*delta_time;
 Y_Velocity = Y_Velocity + Y_Acceleration*delta_time;
 cur_rotation = cur_rotation + rotate_rate*delta_time;
}
             
void Action_Prop::render()
{
 if(in_use) Spr_Action_Prop->RenderEx(X_Position - Camera_X + Screen_Width/2, Y_Position - Camera_Y + Screen_Height/2, cur_rotation);
}

//Prop Layers
Static_Prop* Static_Props;
Action_Prop* Action_Props;

#endif
